import { BaseEntity } from "src/common/entity/BaseEntity";
import { Entity, Column, ManyToOne, JoinColumn, OneToOne } from "typeorm";
import { Article } from "../article/article.entity";
import { User } from "../user/user.entity";

@Entity("comment", { comment: "评论表" })
export class Comment extends BaseEntity {
  // 点赞数
  @Column({ name: "like_count", comment: "点赞数" })
  likeCount: number;

  // 评论内容
  @Column({ type: "text", comment: "评论内容" })
  content: string;

  // 评论用户
  @OneToOne((type) => User, (users) => users.id)
  @JoinColumn({ name: "user_id" })
  user: string;

  // 评论文章ID
  @OneToOne((type) => Article, (article) => article.id)
  @JoinColumn({ name: "article_id" })
  article: string;

  // 父评论ID
  @ManyToOne((type) => Comment, (comment) => comment.id)
  @JoinColumn({ name: "parent_id" })
  parent: string;
}
